package pl.edu.agh.anomalyids.lerad.aspect.implementation;

import pl.edu.agh.anomalyids.lerad.aspect.AbstractAspect;
import pl.edu.agh.anomalyids.lerad.aspect.enums.AspectType;
import pl.edu.agh.anomalyids.lerad.aspect.enums.Match;
import pl.edu.agh.anomalyids.network.Packet;
import pl.edu.agh.anomalyids.network.Packet.Protocol;
import pl.edu.agh.anomalyids.network.header.Header;
import pl.edu.agh.anomalyids.network.header.impl.HTTPHeader;

public class HttpMethodAspect extends AbstractAspect<String> {

	private static final long serialVersionUID = -262854109572464995L;

	public HttpMethodAspect(String method) {
		super(AspectType.HTTPMETHOD);
		this.values.add(method);
	}

	@Override
	public String toString() {
		return getData().toString();
	}

	@Override
	public Match packetMatchesAspect(Packet packet) {
		Header header = packet.getProtocols().get(Protocol.HTTP);
		if (header != null) {
			HTTPHeader http = (HTTPHeader) header;
			if (validate(http.getRequestMethod())) {
				return Match.SAME;
			} else {
				return Match.DIFFER;
			}
		}
		return Match.UNKNOWN;
	}

}
